import time

from selenium.webdriver.common.by import By

from base.base import Base
class Page(Base):
    # 定位值
    username=(By.ID,"username")
    password=(By.ID,'password')
    login=(By.XPATH,'//*[@id="loginForm"]/button')
    testdy=(By.XPATH,'/html/body/div/h1')
    shangchuan=(By.ID,'uploadFile')
    # 封装
    def username_id(self):
        self.send_keys(self.username,"13485456209")
    def password_id(self):
        self.send_keys(self.password,"1234555uuu")
    def login_xpath(self):
        self.click(self.login)
    def testduanyan(self):
        return self.duanyan(self.testdy)
    def shang(self):
        self.send_keys(self.shangchuan,r"C:\Users\Administrator\Desktop\Screenshot_7.png")
    def alst(self):
        self.alert()
    def slool(self):
        self.switch(500)
    def fengzhuang(self):
        print(self.testduanyan())
        assert self.testduanyan()=="图书管理系统"
        time.sleep(2)
        self.username_id()
        time.sleep(2)
        self.password_id()
        time.sleep(2)
        self.login_xpath()
        time.sleep(2)
        self.alst()
        time.sleep(2)
        self.slool()
        self.shang()
        time.sleep(10)


        #
        # # 识别图片账号 yzsheng
        # def base64_api(img=r'D:\2008ACode\data\fullcaptcha1.png', typeid=1002):
        #     with open(img, 'rb') as f:
        #         base64_data = base64.b64encode(f.read())
        #         b64 = base64_data.decode()
        #     sleep(1)
        #     data = {"username": "yzsheng", "password": "123456aA", "typeid": typeid, "image": b64}
        #     result = json.loads(requests.post("http://api.ttshitu.com/predict", json=data).text)
        #     print(result)
        #     if result["success"]:
        #         return result['data']['result']
        #     else:
        #         return result['message']


